﻿#region Copyright ©2008-2011, Technische Universitaet Muenchen

// ====================================================================================================
//
// Last Changed by       $Author: then $
// Last Changed Date     $LastChangedDate: 2009-06-15 08:45:45 +0200 (Mon, 15 Jun 2009) $
// Last Changed Revision $Rev: 194 $
//
// ====================================================================================================

#endregion

#region

using System;
using System.Windows;
using Microsoft.Win32;

#endregion

namespace Tum.CollabXT.Wizard
{
    /// <summary>
    /// Interaction logic for WizardWelcomePage.xaml
    /// </summary>
    internal partial class WizardWelcomePage : InternalConversionWorkflowPage
    {
        /// <summary>
        /// Conversion workflow.
        /// </summary>
        private ConversionWorkflow Workflow;


        /// <summary>
        /// Constructor.
        /// </summary>
        public WizardWelcomePage()
        {
            InitializeComponent();

            Helper.FillInlineCollectionFromString(WelcomeMessage.Inlines, Wizard.Resources.Language.WelcomePage_WelcomeText);
        }

        /// <summary>
        /// Receives the conversion workflow.
        /// </summary>
        /// <param name="workflow">Conversion workflow.</param>
        /// <returns>True, if the workflow has been received correctly, false if not.</returns>
        public override bool InternalReceiveWorkflowHandle(ConversionWorkflow workflow)
        {
            Workflow = workflow;

            Workflow.UpdateButtonState(false, Workflow.Project != null);
            return true;
        }

        /// <summary>
        /// Event handler: "Load" button.
        /// </summary>
        private void buttonLoadProject_Click(object sender, RoutedEventArgs e)
        {
            try
            {
                var openFileDlg = new OpenFileDialog();
                openFileDlg.Filter = Wizard.Resources.Language.ProjectFilesFilter + " (*.ppf)|*.ppf";
                openFileDlg.Multiselect = false;
                openFileDlg.RestoreDirectory = true;

                if (openFileDlg.ShowDialog() == true)
                {
                    Workflow.Reset();
                    Workflow.Project = new ConversionProject(openFileDlg.FileName, Workflow.PluginMgr);
                    Workflow.NextPage();
                }
            }
            catch (Exception)
            {
            }
        }

        /// <summary>
        /// Event handler: "New" button.
        /// </summary>
        private void buttonNewProject_Click(object sender, RoutedEventArgs e)
        {
            Workflow.Reset();
            Workflow.Project = new ConversionProject();

            Workflow.NextPage();
        }
    }
}